#ifndef _MULTI_PATTERN_AC_H_
#define _MULTI_PATTERN_AC_H_


#define ALPHABET_SIZE    256

#define PACKET_LEN       64*1024

#define ACSM_FAIL_STATE  -1

typedef struct ac_pattern_s {
    struct         ac_pattern_s *next;
    unsigned char *ptn;
    unsigned char *case_ptn;
    int            n;
    int            nocase;
    void          *id;
    void          *rule_option_tree;
} ac_pattern_t;

typedef struct ac_state_s {

    /* Next state - based on input character */
    int           next_state[ALPHABET_SIZE];

    /* Failure state - used while building NFA & DFA  */
    int           failure;

    /* List of patterns that end here, if any */
    ac_pattern_t *matchlist;

} ac_state_t;

/*
 * State machine Struct
 */
typedef struct ac_s {

    int            ac_max_states;
    int            ac_num_states;

    ac_pattern_t  *ac_patterns;
    ac_state_t    *ac_state_table;

    int            pattern_num;
    unsigned char *tc;
    void          (*option_tree_free) (void **);
} ac_t;


ac_t   *ac_new(void (*option_tree_free) (void **));

int     ac_add_pattern(ac_t * p, unsigned char *pat, int n, int nocase, void *id);

int     ac_compile(ac_t * acsm, int (*build_tree) (void *id, void **existing_tree));

int     ac_search(ac_t * acsm, unsigned char *tx, int n,
                  int (*match) (void *id, void *tree, int index, void *data),
                  void *data, int *current_state);
                  
void ac_free(ac_t * acsm);

#endif /*_MULTI_PATTERN_AC_H_*/
